package com.facishare.open.mapper;

import com.facishare.open.entity.Blog;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.StatementType;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by linchf on 2016/7/25.
 */
public interface BlogMapper {

    @Select("select * from blog")
    List<Blog> getAllBlogs();

    @Select("select * from blog where id=#{id}")
    Blog getBlogById(long id);

    @Insert("insert into blog(title,date,authername,content) values (#{title},#{date},#{authername},#{content})")
    @SelectKey(before = false,keyProperty = "id",resultType = Long.class,statementType= StatementType.STATEMENT,statement="SELECT LAST_INSERT_ID() AS id")
    long insertAndGetId(Blog blog);

    @Select("<script>select * from blog where 1=1 " +
            "<if test=\"title != null \">and title = #{title}</if>" +
            "<if test=\"date != null \">and date = #{date}</if>" +
            "<if test=\"authername != null \">and authername = #{authername}</if>" +
            "<if test=\"content != null \">and content = #{content}</if>" +
            "</script> ")
    List<Blog> getBlogsByWhere(Blog blog);

}
